import { createI18n } from 'vue-i18n'
import en from './en'
import zh from './zh'
import settings from '@/settings'
import pinia from '@/store'
import {useConfigStore} from '@/store/config'
import * as utilStore from '@/store/util-store'
const messages = { en, zh }

let configString=utilStore.GET_LOCAL_KEY('config') 
console.log('configString',configString);
let configLang=configString && JSON.parse(configString).language;
console.log('configLang',configLang);

let lang=configLang || settings.defaultLanguage
console.log('lang',lang);
const localeData = {
  globalInjection: true, //如果设置true, $t() 函数将注册到全局
  legacy: false, //如果想在composition api中使用需要设置为false
  locale: lang,
  messages // set locale messages
}

export const i18n = createI18n(localeData)
export const setupI18n = {
  install(app) {
    app.use(i18n)
  }
}

// console.log('useConfigStore',useConfigStore);


// const configStore=useConfigStore(pinia) //bug: 持久化会失效

// const localeData = {
//   globalInjection: true, //如果设置true, $t() 函数将注册到全局
//   legacy: false, //如果想在composition api中使用需要设置为false
//   locale: configStore.language,
//   messages // set locale messages
// }

// export const i18n = createI18n(localeData)
// export const setupI18n = {
//   install(app) {
//     app.use(i18n)
//   }
// }
